home *** CD-ROM | disk | FTP | other *** search
- SBUF.PUB(3C) Last changed: 10-20-98
-
-
- NNAAMMEE
- ssttrreeaammbbuuff - Public interface of character buffering class
-
- SSYYNNOOPPSSIISS
- ##iinncclluuddee <<iioossttrreeaamm..hh>>
-
- ttyyppeeddeeff lloonngg ssttrreeaammooffff,, ssttrreeaammppooss;;
- ccllaassss iiooss {{
- ppuubblliicc::
- eennuumm sseeeekk__ddiirr {{ bbeegg,, ccuurr,, eenndd }};;
- eennuumm ooppeenn__mmooddee {{ iinn,, oouutt,, aattee,, aapppp,, ttrruunncc,, nnooccrreeaattee,, nnoorreeppllaaccee }}
- ;;
- //// aanndd lloottss ooff ootthheerr ssttuuffff ...... SSeeee iiooss((33CC))
- }} ;;
-
- ccllaassss ssttrreeaammbbuuff {{
- ppuubblliicc ::
-
- iinntt iinn__aavvaaiill(());;
- iinntt oouutt__wwaaiittiinngg(());;
- iinntt ssbbuummppcc(());;
- ssttrreeaammbbuuff** sseettbbuuff((cchhaarr** ppttrr,, iinntt lleenn));;
- ssttrreeaammppooss sseeeekkppooss((ssttrreeaammppooss,, iinntt ==iiooss::::iinn||iiooss::::oouutt));;
- ssttrreeaammppooss sseeeekkooffff((ssttrreeaammooffff,, sseeeekk__ddiirr,, iinntt ==iiooss::::iinn||iiooss::::oouutt));;
- iinntt ssggeettcc(());;
- iinntt ssggeettnn((cchhaarr** ppttrr,, iinntt nn));;
- iinntt ssnneexxttcc(());;
- iinntt ssppuuttbbaacckkcc((cchhaarr));;
- iinntt ssppuuttcc((iinntt cc));;
- iinntt ssppuuttnn((ccoonnsstt cchhaarr** ss,, iinntt nn));;
- vvooiidd ssttoosssscc(());;
- vviirrttuuaall iinntt ssyynncc(());;
- }};;
-
- IIMMPPLLEEMMEENNTTAATTIIOONN
- IRIX systems
-
- DDEESSCCRRIIPPTTIIOONN
- The ssttrreeaammbbuuff class supports buffers into which characters can be
- inserted (put) or from which characters can be fetched (gotten).
- Abstractly, such a buffer is a sequence of characters together with
- one or two pointers (a get and/or a put pointer) that define the
- location at which characters are to be inserted or fetched. The
- pointers should be thought of as pointing between characters rather
- than at them. This makes it easier to understand the boundary
- conditions (a pointer before the first character or after the last).
- Some of the effects of getting and putting are defined by this class
- but most of the details are left to specialized classes derived from
- ssttrreeaammbbuuff. (See ffiilleebbuuff(3C), ssssbbuuff(3C), and ssttddiioobbuuff(3C).)
-
- Classes derived from ssttrreeaammbbuuff vary in their treatments of the get and
- put pointers. The simplest are unidirectional buffers which permit
- only gets or only puts. Such classes serve as pure sources
- (producers) or sinks (consumers) of characters. Queuelike buffers
- (see ssttrrssttrreeaamm(3C) and ssssbbuuff(3C)) have a put and a get pointer which
- move independently of each other. In such buffers, characters that
- are stored are held (queued) until they are later fetched. Filelike
- buffers (such as ffiilleebbuuff, see ffiilleebbuuff(3C)) permit both gets and puts
- but have only a single pointer. (An alternative description is that
- the get and put pointers are tied together so that when one moves the
- other also moves.)
-
- Most ssttrreeaammbbuuff member functions are organized into two phases. As far
- as possible, operations are performed inline by storing into or
- fetching from arrays (the ggeett aarreeaa and the ppuutt aarreeaa, which together
- form the rreesseerrvvee aarreeaa, or bbuuffffeerr). From time to time, virtual
- functions are called to deal with collections of characters in the get
- and put areas. That is, the virtual functions are called to fetch
- more characters from the ultimate producer or to flush a collection of
- characters to the ultimate consumer. Generally, the user of a
- ssttrreeaammbbuuff does not have to know anything about these details, but some
- of the public members pass back information about the state of the
- areas. More information about these areas is provided in the
- ssbbuuff..pprroott(3C) man page, which describes the protected interface.
-
- The following assumptions are made in the following descriptions of
- the public member functions of the ssttrreeaammbbuuff class.
-
- * _i, _n, and _l_e_n are iinntts.
-
- * _c is an iinntt. It always holds a ``character'' value or EEOOFF. A
- ``character'' value is always positive even when cchhaarr is normally
- sign extended.
-
- * _s_b and _s_b_1 are ssttrreeaammbbuuff**s.
-
- * _p_t_r is a cchhaarr**.
-
- * _o_f_f is a ssttrreeaammooffff.
-
- * _p_o_s is a ssttrreeaammppooss.
-
- * _d_i_r is a sseeeekk__ddiirr.
-
- * _m_o_d_e is an iinntt representing an ooppeenn__mmooddee.
-
- Public member functions:
-
- _i==_s_b-->>iinn__aavvaaiill(())
- Returns the number of characters that are immediately available
- in the get area for fetching. _i characters may be fetched with a
- guarantee that no errors will be reported.
-
- _i==_s_b-->>oouutt__wwaaiittiinngg(())
- Returns the number of characters in the put area that have not
- been consumed (by the ultimate consumer).
-
- _c==_s_b-->>ssbbuummppcc(())
- Moves the get pointer forward one character and returns the
- character it moved past. Returns EEOOFF if the get pointer is
- currently at the end of the sequence.
-
- _p_o_s==_s_b-->>sseeeekkooffff((_o_f_f,, _d_i_r,, _m_o_d_e))
- Repositions the get and/or put pointers. _m_o_d_e specifies whether
- the put pointer (iiooss::::oouutt bit set) or the get pointer (iiooss::::iinn
- bit set) is to be modified. Both bits may be set in which case
- both pointers should be affected. _o_f_f is interpreted as a byte
- offset. (Notice that it is a signed quantity.) The meanings of
- possible values of _d_i_r are
-
- iiooss::::bbeegg
- The beginning of the stream.
-
- iiooss::::ccuurr
- The current position.
-
- iiooss::::eenndd
- The end of the stream (end of file.)
-
- Not all classes derived from ssttrreeaammbbuuff support repositioning.
- sseeeekkooffff(()) will return EEOOFF if the class does not support repositioning.
- If the class does support repositioning, sseeeekkooffff(()) will return the new
- position or EEOOFF on error.
-
- _p_o_s==_s_b-->>sseeeekkppooss((_p_o_s,, _m_o_d_e))
- Repositions the streambuf get and/or put pointer to _p_o_s. _m_o_d_e
- specifies which pointers are affected as for sseeeekkooffff(()). Returns
- _p_o_s (the argument) or EEOOFF if the class does not support
- repositioning or an error occurs. In general a ssttrreeaammppooss should
- be treated as a ``magic cookie'' and no arithmetic should be
- performed on it. The following two values have special meaning:
-
- ssttrreeaammppooss((00))
- The beginning of the file.
-
- ssttrreeaammppooss((EEOOFF))
- Used as an error indication.
-
- _c==_s_b-->>ssggeettcc(())
- Returns the character after the get pointer. Contrary to what
- most people expect from the name IT DOES NOT MOVE THE GET
- POINTER. Returns EEOOFF if there is no character available.
-
- _s_b_1==_s_b-->>sseettbbuuff((_p_t_r,, _l_e_n,, _i))
- Offers the _l_e_n bytes starting at _p_t_r as the reserve area. If _p_t_r
- is null or _l_e_n is zero or less, then an unbuffered state is
- requested. Whether the offered area is used, or a request for
- unbuffered state is honored depends on details of the derived
- class. sseettbbuuff(()) normally returns _s_b, but if it does not accept
- the offer or honor the request, it returns 0.
-
- _i==_s_b-->>ssggeettnn((_p_t_r,, _n))
- Fetches the _n characters following the get pointer and copies
- them to the area starting at _p_t_r. When there are fewer than _n
- characters left before the end of the sequence ssggeettnn(()) fetches
- whatever characters remain. ssggeettnn(()) repositions the get pointer
- following the fetched characters and returns the number of
- characters fetched.
-
- _c==_s_b-->>ssnneexxttcc(())
- Moves the get pointer forward one character and returns the
- character following the new position. It returns EEOOFF if the
- pointer is currently at the end of the sequence or is at the end
- of the sequence after moving forward.
-
- _i==_s_b-->>ssppuuttbbaacckkcc((_c))
- Moves the get pointer back one character. _c must be the current
- content of the sequence just before the get pointer. The
- underlying mechanism may simply back up the get pointer or may
- rearrange its internal data structures so the _c is saved. Thus
- the effect of ssppuuttbbaacckkcc(()) is undefined if _c is not the character
- before the get pointer. ssppuuttbbaacckkcc(()) returns EEOOFF when it fails.
- The conditions under which it can fail depend on the details of
- the derived class.
-
- _i==_s_b-->>ssppuuttcc((_c))
- Stores _c after the put pointer, and moves the put pointer past
- the stored character; usually this extends the sequence. It
- returns EEOOFF when an error occurs. The conditions that can cause
- errors depend on the derived class.
-
- _i==_s_b-->>ssppuuttnn((_p_t_r,, _n))
- Stores the _n characters starting at _p_t_r after the put pointer and
- moves the put pointer past them. ssppuuttnn(()) returns _i, the number
- of characters stored successfully. Usually, _i is _n, but it may
- be less when errors occur.
-
- _s_b-->>ssttoosssscc(())
- Moves the get pointer forward one character. If the pointer
- started at the end of the sequence this function has no effect.
-
- _i==_s_b-->>ssyynncc(())
- Establishes consistency between the internal data structures and
- the external source or sink. The details of this function depend
- on the derived class. Usually this ``flushes'' any characters
- that have been stored but not yet consumed, and ``gives back''
- any characters that may have been produced but not yet fetched.
- ssyynncc(()) returns EEOOFF to indicate errors.
-
- CCAAVVEEAATTSS
- sseettbbuuff does not really belong in the public interface. It is there
- for compatibility with the stream package.
-
- Requiring the program to provide the previously fetched character to
- ssppuuttbbaacckk is probably a botch.
-
- SSEEEE AALLSSOO
- iiooss(3C), iissttrreeaamm(3C), oossttrreeaamm(3C), ssbbuuff..pprroott(3C)
-
- This man page is available only online.
-
-